
package com.gec.system.controller;

import com.gec.system.util.OssTemplate;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@Api(tags = "图片视频上传控制器")
@RequestMapping("/admin/system/upload")
@CrossOrigin  // 解决跨域问题
public class SysUploadController {

    @Autowired
    private OssTemplate ossTemplate;

    // uploadImage
//    @PostMapping("/uploadImage")
//    public Result uploadImage(MultipartFile uploadImage) throws IOException {
//
//
//        System.out.println("进入上传控制器");
//        String imagePath = this.ossTemplate.upload(uploadImage.getOriginalFilename(), uploadImage.getInputStream());
//        System.out.println("图片路径："+imagePath);
//        return Result.ok(imagePath);
//    }

    @PostMapping("/uploadImage")
    public String uploadImage(MultipartFile uploadImage) throws IOException {


        System.out.println("进入上传控制器");
        String imagePath = this.ossTemplate.upload(uploadImage.getOriginalFilename(), uploadImage.getInputStream());

        System.out.println("imagePath================"+imagePath);
        return imagePath;
    }


}

